#include<iostream>
#include<string>
using namespace std;
struct {
	string s;
	int a, b;
} a[1010];
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i].s >> a[i].a >> a[i].b;
	int m;
	cin >> m;
	for (int i = 1; i <= m; i++)
	{
		int temp;
		cin >> temp;
		for (int i = 1; i <= n; i++)
		{
			if (a[i].a == temp)
			{
				cout << a[i].s << ' ' << a[i].b << endl;
				break;
			}
		}
	}
	return 0;
}